﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 转换条件
/// </summary>
public enum Transition
{
    NullTransition = 0,
    AfterSpawn,
    SawRole
}
/// <summary>
/// 状态
/// </summary>
public enum StateID
{
    NullStateID = 0,
    MoveToFront,
    MoveToRole
}

public abstract class FSMState
{
    protected StateID StateId;
    public StateID stateId
    {
        get { return StateId; }
    }
    /// <summary>
    /// 存储当前状态可以转换到的状态
    /// </summary>
    protected Dictionary<Transition, StateID> map = new Dictionary<Transition, StateID>();

    public void AddTransition(Transition trans, StateID id)
    {
        if (trans == Transition.NullTransition || id == StateID.NullStateID)
        {
            Debug.LogError("trans或者id为空");
            return;
        } 
        if (map.ContainsKey(trans) )
        {
            Debug.LogError("trans已存在，若要覆盖请先删除已存在的trans");
            return;
        }

        map.Add(trans, id);
    } 
    public void DeleteTransition(Transition trans)
    {
        if (map.ContainsKey(trans) == false)
        {
            Debug.LogError("map中并没有包含想要删除的trans");
            return;
        }

        map.Remove(trans);
    } 
    /// <summary>
    /// 根据传递过来的转换条件，判断是否可以发生转换
    /// </summary>
    /// <param name="trans">转换条件枚举值</param>
    /// <returns>状态ID</returns>
    public StateID GetOutputState(Transition trans)
    {
        if (map.ContainsKey(trans))
        {
            return map[trans];
        } 
        return StateID.NullStateID;
    }

    public abstract void DoBeforeEntering();
    public abstract void DoBeforeLeaving();
    public abstract void DoCurrentState();//当前状态中做的事情
}